#-*- encoding:utf-8 -*-
import tensorflow as tf
import dnn_net
from dnn_train import PATH_MODEL_SAVE
import numpy as np
import pre_handle_data as p_data
import matplotlib.pyplot as plt
from matplotlib.font_manager import *
plt.rcParams['font.sans-serif']=['simhei']
sys.setdefaultencoding('utf8')
matplotlib.rcParams['axes.unicode_minus'] = False

#参数设置区域
arr_cur_trace,d=p_data.get_single_noise30__data()
noise_rate="30"
threshold=0.5

first_breaking_t=0;
feed_data=tf.placeholder(tf.float32,[None,dnn_net.INPUT_NODE],name="feed_data")
output=dnn_net.get_dnn_net(feed_data)
init=tf.global_variables_initializer()
saver=tf.train.Saver()
with tf.Session() as sess:
    sess.run(init)
    ckpt=tf.train.get_checkpoint_state(PATH_MODEL_SAVE)
    if ckpt and ckpt.model_checkpoint_path:
        saver.restore(sess,ckpt.model_checkpoint_path)
        global_step=ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1]
        output=sess.run(output,feed_dict={feed_data:arr_cur_trace})
        output=np.array(output)
for i in range(len(output)):
    if  output[i]>threshold:
        threshold=output[i]
        first_breaking_t=i+1
point=np.zeros(200)
for i in range(200):
    point[i]=i+1
print('the first breaking point is %d' % first_breaking_t)
plt.figure(1)
plt.subplot(1,2,1)
l1,=plt.plot(output[:],point[:],color='red')
plt.title('DNN网络对每个采样点映射出的概率')
plt.xlim(-0.1,1.1)
plt.ylim(1,200)
ax=plt.gca()
ax.invert_yaxis()
plt.ylabel('点号')
plt.xlabel('概率')

plt.subplot(1,2,2)
l3=plt.plot(d,point)
l4=plt.plot([-0.5,0.5],[first_breaking_t,first_breaking_t])
plt.text(0.6,first_breaking_t,str(first_breaking_t))
plt.title('被预测的雷克子波'+'(噪声为'+noise_rate+'%)')
plt.xlim(-1,1)
plt.ylim(1,200)
ax=plt.gca()
ax.invert_yaxis()
plt.ylabel('点号')
plt.xlabel('振幅')
plt.show()
